package CA;


import java.io.File;
import java.util.ArrayList;
import java.util.List;

import StringComparision.StringDistances;



import junit.framework.TestCase;


public class DistanceTests extends TestCase {

	
//	private final String MainExamineLocation = "C:/SignatureOutput/noscan/UnitTests/";
	private final String MainExaminLocation = System.getProperty("user.dir") + "/UnitTestData/";

	protected void setUp() throws Exception {
		super.setUp();
	}

	protected void tearDown() throws Exception {
		super.tearDown();
	}
	

	
	
	
	// test the calculations for Complete Line counts
	
	public void testCompleteLineCountCalculations()
	{
		String compareFile = MainExaminLocation+"/ScanTypes/";
		Helper h = new Helper();
		CrashSuper cs = new CrashSuper();
		List<FileInfo> fileList = new ArrayList<FileInfo>();
		fileList=cs.getFileList(compareFile);
		cs.BuildFileData(fileList, compareFile, false);
		
	//	assertEquals(fileList.get(h.getArrayIndex(fileList,"TotalStringTests")).getAvgByLineTotalStringGenericDistance(),113.5);
	//	assertEquals(fileList.get(h.getArrayIndex(fileList,"TotalStringTests")).getAvgByLineTotalStringLCS(),25.18);
		
	}
	

	

	
	// Check to make sure that all the distance comparisions are being done correctly among multiple files
	public void testStringComparisonsMultipleFilesNoDifference()
	{
		String compareFile = MainExaminLocation+"/StringDifferenceMultiple/NoDifference/";
		Helper h = new Helper();
		CrashSuper cs = new CrashSuper();
		List<FileInfo> fileList = new ArrayList<FileInfo>();
		fileList=cs.getFileList(compareFile);
		cs.BuildFileData(fileList, compareFile, false);
	
		
		//LCS Between same is 98
	//	assertEquals(fileList.get(0).getLCS(),98);
		
		// get generic difference
	//	assertEquals(fileList.get(0).getGenericStringDistanceTotal(),0); // They are the same. No difference
		
		// get Jaro difference 
	//	assertEquals(fileList.get(0).getJaro(),28.0); 
			
		// get JaroWinkler difference 
	//	assertEquals(fileList.get(0).getJaroWinkler(),28.0); 
		
		// get Levenstein difference 
	//	assertEquals(fileList.get(0).getLevenDistanceTotal(),0.0); 
	
		
		// get SmithWaterman difference 
	//	assertEquals(fileList.get(0).getSmithWaterman(),3572.0); 
		
		
		// get Needleman-Wunsch difference 
	//	assertEquals(fileList.get(0).getNW(),3572.0); 
		
		
		// get Jaccard difference -- Not working
		//	assertEquals(fileList.get(0).getJaccardTotal(),0.0); 
			

		// get ScaledLevenstein difference 
	//	assertEquals(fileList.get(0).getScaledLevenstein(),0.0); 
		
		// get MongeElkan difference 
		//assertEquals(fileList.get(0).getMongeElkan(),0.0); 
	
		
		
		
	}

	
	public void testStringComparisonsMultipleFilesAB()
	{
		String compareFile = MainExaminLocation+"/StringDifferenceMultiple/2FilesAB/";
		Helper h = new Helper();
		CrashSuper cs = new CrashSuper();
		List<FileInfo> fileList = new ArrayList<FileInfo>();
		fileList=cs.getFileList(compareFile);
		cs.BuildFileData(fileList, compareFile, false);
	
		
		//LCS 
	//	assertEquals(fileList.get(0).getLCS(),93);
		
		// get generic difference
	//	assertEquals(fileList.get(0).getGenericStringDistanceTotal(),1475);
				
	
		// get Jaro difference 
	//	assertEquals(fileList.get(0).getJaro(),16.29); 
			
		// get JaroWinkler difference 
	//	assertEquals(fileList.get(0).getJaroWinkler(),18.88); 
		
		// get Levenstein difference 
	//	assertEquals(fileList.get(0).getLevenDistanceTotal(),-1436.0); 
	
		
		// get SmithWaterman difference 
	//	assertEquals(fileList.get(0).getSmithWaterman(),961.0); 
		
		
		// get Needleman-Wunsch difference 
	//	assertEquals(fileList.get(0).getNW(),448.0); 
		

		// get ScaledLevenstein difference 
	//	assertEquals(fileList.get(0).getScaledLevenstein(),0.0); 
		
		// get MongeElkan difference 
		//assertEquals(fileList.get(0).getMongeElkan(),0.0); 
	
		// get Jaccard difference -- Not working
		//	assertEquals(fileList.get(0).getCompleteJaccardDistanceTotal(),0); 
			
		
		
	}
	
	
	public void testStringComparisonsMultipleFilesBC()
	{
		String compareFile = MainExaminLocation+"/StringDifferenceMultiple/2FilesBC/";
		Helper h = new Helper();
		CrashSuper cs = new CrashSuper();
		List<FileInfo> fileList = new ArrayList<FileInfo>();
		fileList=cs.getFileList(compareFile);
		cs.BuildFileData(fileList, compareFile, false);
	
		
		//LCS 
	//	assertEquals(fileList.get(0).getLCS(),93);
		
		// get generic difference
	//	assertEquals(fileList.get(0).getGenericStringDistanceTotal(),1454); 
				
	
		// get Jaro difference 
	//	assertEquals(fileList.get(0).getJaro(),17.09); 
			
		// get JaroWinkler difference 
	//	assertEquals(fileList.get(0).getJaroWinkler(),19.77); 
		
		// get Levenstein difference 
	//	assertEquals(fileList.get(0).getLevenDistanceTotal(),-1415.0); 
	
		
		// get SmithWaterman difference 
	//	assertEquals(fileList.get(0).getSmithWaterman(),1000.0); 
		
		
		// get Needleman-Wunsch difference 
	//	assertEquals(fileList.get(0).getNW(),513.0); 
		

		// get ScaledLevenstein difference 
	//DK	assertEquals(fileList.get(0).getScaledLevenstein(),0.0); 
		
		// get MongeElkan difference 
		//DK	assertEquals(fileList.get(0).getMongeElkan(),0.0); 
	
		// get Jaccard difference -- Not working
		//DK	assertEquals(fileList.get(0).getCompleteJaccardDistanceTotal(),0); 
			
		
		
	}
	
	
	public void testStringComparisonsMultipleFilesAC()
	{
		String compareFile = MainExaminLocation+"/StringDifferenceMultiple/2FilesAC/";
		Helper h = new Helper();
		CrashSuper cs = new CrashSuper();
		List<FileInfo> fileList = new ArrayList<FileInfo>();
		fileList=cs.getFileList(compareFile);
		cs.BuildFileData(fileList, compareFile, false);
	
		
		//LCS
	//	assertEquals(fileList.get(0).getLCS(),98);
		
		// get generic difference
	//	assertEquals(fileList.get(0).getGenericStringDistanceTotal(),62); 
				
	
		// get Jaro difference 
	//	assertEquals(fileList.get(0).getJaro(),27.77); 
			
		// get JaroWinkler difference 
	//	assertEquals(fileList.get(0).getJaroWinkler(),27.86); 
		
		// get Levenstein difference 
	//	assertEquals(fileList.get(0).getLevenDistanceTotal(),-61.0); 
	
		
		// get SmithWaterman difference 
	//	assertEquals(fileList.get(0).getSmithWaterman(),3518.0); 
		
		
		// get Needleman-Wunsch difference 
	//	assertEquals(fileList.get(0).getNW(),3470.0); 
		

		// get ScaledLevenstein difference 
	//DK	assertEquals(fileList.get(0).getScaledLevenstein(),0.0); 
		
		// get MongeElkan difference 
		//DK	assertEquals(fileList.get(0).getMongeElkan(),0.0); 
	
		// get Jaccard difference -- Not working
		//DK	assertEquals(fileList.get(0).getCompleteJaccardDistanceTotal(),0); 
			
		
		
	}

	public void testStringComparisonsMultipleFilesABC()
	{
		String compareFile = MainExaminLocation+"/StringDifferenceMultiple/3FilesABC/";
		Helper h = new Helper();
		CrashSuper cs = new CrashSuper();
		List<FileInfo> fileList = new ArrayList<FileInfo>();
		fileList=cs.getFileList(compareFile);
		cs.BuildFileData(fileList, compareFile, false);
	
		
		// Total number of files
		assertEquals(fileList.get(0).getNumberOfFiles(),3);
		
		// Total number of lines
		assertEquals(fileList.get(0).getTotalNumberofLines(),92);
		
		
		//LCS
	//	assertEquals(fileList.get(0).getLCS(),98);
		
		// get generic difference
	//	assertEquals(fileList.get(0).getGenericStringDistanceTotal(),2991); 
				
	
		// get Jaro difference 
	//	assertEquals(fileList.get(0).getJaro(),61.14); 
			
		// get JaroWinkler difference 
	//	assertEquals(fileList.get(0).getJaroWinkler(),66.51); 
		
		// get Levenstein difference 
	//	assertEquals(fileList.get(0).getLevenDistanceTotal(),-2912.0); 
	
		
		// get SmithWaterman difference 
	//	assertEquals(fileList.get(0).getSmithWaterman(),5479.0); 
		
		
		// get Needleman-Wunsch difference 
	//	assertEquals(fileList.get(0).getNW(),4431.0); 
		

		// get ScaledLevenstein difference 
	//DK	assertEquals(fileList.get(0).getScaledLevenstein(),0.0); 
		
		// get MongeElkan difference 
		//DK	assertEquals(fileList.get(0).getMongeElkan(),0.0); 
	
		// get Jaccard difference -- Not working
		//DK	assertEquals(fileList.get(0).getCompleteJaccardDistanceTotal(),0); 
			
		
		// test LCS average
	//	assertEquals(fileList.get(0).getLCSAvgByLine(),1.07);
	//	assertEquals(fileList.get(0).getLCSAvgByFile(),32.67);
		
	
		// test GD average
	//	assertEquals(fileList.get(0).getGDAvgByLine(),32.51);
	//	assertEquals(fileList.get(0).getGDAvgByFile(),997.0);
		
		
		// test Jaro average
	//	assertEquals(fileList.get(0).getJaroAvgByLine(),.66);
	//	assertEquals(fileList.get(0).getJaroAvgByFile(),20.38);
		
		
		// test JaroWinkler average
	//	assertEquals(fileList.get(0).getJaroWinklerAvgByLine(),.72);
	//	assertEquals(fileList.get(0).getJaroWinklerAvgByFile(),22.17);
		
		// test Leven average
//		assertEquals(fileList.get(0).getLevenAvgByLine(),-31.65);
//		assertEquals(fileList.get(0).getLevenAvgByFile(),-970.67);
		
		// test SW average
	//	assertEquals(fileList.get(0).getSWAvgByLine(),59.55);
	//	assertEquals(fileList.get(0).getSWAvgByFile(),1826.33);
		
		// test NW average
	//	assertEquals(fileList.get(0).getNWAvgByLine(),48.16);
	//	assertEquals(fileList.get(0).getNWAvgByFile(),1477.0);	
		
	}
	
	
	// Do the same thing as above, but run it against a folder with 2 things in it.
	// It should produce similar results, just 2x
	// This needs to be altered so that numerous files are being looked at.

	
	public void testStringComparisonsMultipleFilesABCV2()
	{
		String compareFile = MainExaminLocation+"/StringDifferenceMultiple/3FilesABCV2/";
		Helper h = new Helper();
		StringDistances sd = new StringDistances();
		CrashSuper cs = new CrashSuper();
		List<FileInfo> fileList = new ArrayList<FileInfo>();
		fileList=cs.getFileList(compareFile);
		cs.BuildFileData(fileList, compareFile, false);
	
		
		// Total number of files
		assertEquals(fileList.get(0).getNumberOfFiles(),3);
		assertEquals(fileList.get(1).getNumberOfFiles(),3);
		
		
		// Total number of lines
		assertEquals(fileList.get(0).getTotalNumberofLines(),92);
		assertEquals(fileList.get(1).getTotalNumberofLines(),92);
		
		//LCS
	//	assertEquals(fileList.get(0).getLCS(),98);
	//	assertEquals(fileList.get(1).getLCS(),98);
		
		// get generic difference
	//	assertEquals(fileList.get(0).getGenericStringDistanceTotal(),2991); 
	//	assertEquals(fileList.get(1).getGenericStringDistanceTotal(),2991); 		
	
		// get Jaro difference 
	//	assertEquals(fileList.get(0).getJaro(),61.14); 
//		assertEquals(fileList.get(1).getJaro(),61.14); 
		
		// get JaroWinkler difference 
	//	assertEquals(fileList.get(0).getJaroWinkler(),66.51); 
	//	assertEquals(fileList.get(1).getJaroWinkler(),66.51); 
		
		// get Levenstein difference 
	//	assertEquals(fileList.get(0).getLevenDistanceTotal(),-2912.0); 
	//	assertEquals(fileList.get(1).getLevenDistanceTotal(),-2912.0); 
	
		
		// get SmithWaterman difference 
	//	assertEquals(fileList.get(0).getSmithWaterman(),5479.0); 
	//	assertEquals(fileList.get(1).getSmithWaterman(),5479.0); 
		
		// get Needleman-Wunsch difference 
	//	assertEquals(fileList.get(0).getNW(),4431.0); 
	//	assertEquals(fileList.get(1).getNW(),4431.0); 
			
		
		// test LCS average
	//	assertEquals(fileList.get(0).getLCSAvgByLine(),1.07);
	//	assertEquals(fileList.get(0).getLCSAvgByFile(),32.67);
	//	assertEquals(fileList.get(1).getLCSAvgByLine(),1.07);
	//	assertEquals(fileList.get(1).getLCSAvgByFile(),32.67);
		
	
		// test GD average
	//	assertEquals(fileList.get(0).getGDAvgByLine(),32.51);
	//	assertEquals(fileList.get(0).getGDAvgByFile(),997.0);
	//	assertEquals(fileList.get(1).getGDAvgByLine(),32.51);
	//	assertEquals(fileList.get(1).getGDAvgByFile(),997.0);
		
		
		// test Jaro average
	//	assertEquals(fileList.get(0).getJaroAvgByLine(),.66);
	//	assertEquals(fileList.get(0).getJaroAvgByFile(),20.38);
	//	assertEquals(fileList.get(1).getJaroAvgByLine(),.66);
	//	assertEquals(fileList.get(1).getJaroAvgByFile(),20.38);
		
		
		// test JaroWinkler average
		//assertEquals(fileList.get(0).getJaroWinklerAvgByLine(),.72);
		//assertEquals(fileList.get(0).getJaroWinklerAvgByFile(),22.17);
		//assertEquals(fileList.get(1).getJaroWinklerAvgByLine(),.72);
		//assertEquals(fileList.get(1).getJaroWinklerAvgByFile(),22.17);
		
		// test Leven average
//		assertEquals(fileList.get(0).getLevenAvgByLine(),-31.65);
//		assertEquals(fileList.get(0).getLevenAvgByFile(),-970.67);
//		assertEquals(fileList.get(1).getLevenAvgByLine(),-31.65);
//		assertEquals(fileList.get(1).getLevenAvgByFile(),-970.67);
		
		// test SW average
	//	assertEquals(fileList.get(0).getSWAvgByLine(),59.55);
	//	assertEquals(fileList.get(0).getSWAvgByFile(),1826.33);
	//	assertEquals(fileList.get(1).getSWAvgByLine(),59.55);
	//	assertEquals(fileList.get(1).getSWAvgByFile(),1826.33);
		
		// test NW average
	//	assertEquals(fileList.get(0).getNWAvgByLine(),48.16);
	//	assertEquals(fileList.get(0).getNWAvgByFile(),1477.0);	
	//	assertEquals(fileList.get(1).getNWAvgByLine(),48.16);
	//	assertEquals(fileList.get(1).getNWAvgByFile(),1477.0);
		
		
		// Now test out the totals for all of them. The averages should still be the same
		
		
		// LCS
	//	assertEquals(sd.getLCSMultiFolderAVGByLine(fileList),1.07);
	//	assertEquals(sd.getLCSMultiFolderAVGByFile(fileList),32.67);
		
	
		// GD
	//	assertEquals(sd.getGenericDistanceMultiFolderAVGByFile(fileList),997.0);
	//	assertEquals(sd.getGenericDistanceMultiFolderAVGByLine(fileList),32.51);
		
		
		//NW
	//	assertEquals(sd.getNWMultiFolderAVGByFile(fileList),1477.0);
	//	assertEquals(sd.getNWMultiFolderAVGByLine(fileList),48.16);
		
		
		// test the total string averages
		// LCS
	//	assertEquals(sd.getLCSTotalStringAvgByLine(fileList),1.07);
	//	assertEquals(sd.getLCSMultiFolderAVGByFile(fileList),32.67);
		
	
		// GD
	//	assertEquals(sd.getGenericDistanceMultiFolderAVGByFile(fileList),997.0);
	//	assertEquals(sd.getGenericDistanceMultiFolderAVGByLine(fileList),32.51);
		
		
		//NW
	//	assertEquals(sd.getNWMultiFolderAVGByFile(fileList),1477.0);
	//	assertEquals(sd.getNWMultiFolderAVGByLine(fileList),48.16);
			
		
		
		
		// More distances can be added as they are incorproated
		
	}
	
	
	
	
	// Test out total string values as well.
	
	
	
	
	
	// I could add tests for the secondString compononents, but I don't think that is very worthwhile now.
	
	
	
	
	
	

}
